 #include <boost/lexical_cast.hpp>

#include <skyroad/service/service_constants.hpp>
#include <skyroad/service/service.hpp>
#include <skyroad/service/routers/request_router.hpp>
#include <skyroad/bus/bus.hpp>

request_router::request_router(bus& bus) : router(bus) 
{

}

void request_router::route(message& msg)
{
    static service* moni_srv = host().find_service(1981);
    static service* up_srv = host().find_service(1982);

    if (msg.destination().size() < 3)
    {
        return;
    }

    if (msg.destination()[0] != st_business)
    {
        return;
    }

    int srv_id = msg.destination()[1];
    service* srv = host().find_service(srv_id);

    if (moni_srv)
    {
        moni_srv->handle_message(msg);
    }
    if (srv)
    {
        srv->handle_message(msg);
    }
    else if (up_srv)
    {
        up_srv->handle_message(msg);
    }
}


